#!/usr/bin/env ruby
#
# Geocodes the input address
# This should be run from the state directory
#
require File.join(File.dirname(__FILE__),'/util')

include Util

class Geocode

  attr_writer :verbose

  def initialize
    @verbose = true
  end

  def geocode_args(argv)
    address = ''
    ARGV.map { |x| address += ' ' + x }
    address.strip!
    geocode address
  end    

  # Geocodes the address, and you may pass in a state. We need the
  # second argument because of this problem -- we may have something
  # like: California/LosAngeles/MarVista
  def geocode(address,state = nil)
    
    # Try to get it from the file
    # The problem is that we may have something like
    # California/LosAngeles/MarVista
    if File.exists? address
      city   = File.basename address
      if !state
        state  = File.basename(File.dirname(File.expand_path(address)))
      end
      address = Util::un_camel_case(city) + ", " + Util::un_camel_case(state)
    end
    
    return Util::geocode(address, @verbose)
  end
end
